package com.example.demo.controller;


import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import com.example.demo.domain.Bo.AddRoleBo;
import com.example.demo.domain.Role;
import com.example.demo.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
@Api(value = "role",tags = "角色控制器")
public class RoleController {

    @Autowired
    private IRoleService roleService;


    @ApiOperation("增加角色")
    @PostMapping("/addRole")
    public R addRole(@RequestBody AddRoleBo bo){
        Role role = new Role();
        role.setRoleName(bo.getRoleName());
        role.setRemark(bo.getRemark());

        LoginUser loginUser = UserUtil.getLoginUser();//获取当前登录账号
        role.setCreateBy(loginUser.getUserId());
        roleService.addRole(role);
        return R.success();
    }
}
